package com.sc.nft.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dao.SysMemberDao;
import com.sc.nft.dao.UserCreatorPhoneRecordDao;
import com.sc.nft.entity.SysMember;
import com.sc.nft.entity.UserCreatorPhoneRecord;
import com.sc.nft.entity.dto.AdminUserCreatorPhoneRecordDTO;
import com.sc.nft.entity.dto.CreatorPhoneRecordDTO;
import com.sc.nft.entity.vo.AdminUserCreatorPhoneRecordVO;
import com.sc.nft.pool.SysMemberPool;
import com.sc.nft.service.UserCreatorPhoneRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author 朱梦晨
 * @Description: 修改品牌手机号 服务接口实现
 * @date 2024-07-13
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class UserCreatorPhoneRecordServiceImpl implements UserCreatorPhoneRecordService {



    public final UserCreatorPhoneRecordDao userCreatorPhoneRecordDao;

    public final SysMemberDao sysMemberDao;
    /**
     * 增加修改手机号记录
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addUserCreatorPhoneRecord(CreatorPhoneRecordDTO creatorPhoneRecordDTO){
        UserCreatorPhoneRecord userCreatorPhoneRecord = new UserCreatorPhoneRecord();
        if (StringUtils.isNotBlank(creatorPhoneRecordDTO.getUpdateFrontTel())){
            userCreatorPhoneRecord.setUpdateFrontTel(creatorPhoneRecordDTO.getUpdateFrontTel());
        }
        userCreatorPhoneRecord.setDaoName(creatorPhoneRecordDTO.getDaoName());
        userCreatorPhoneRecord.setUpdateAfterTel(creatorPhoneRecordDTO.getUpdateAfterTel());
        userCreatorPhoneRecord.setDaoId(creatorPhoneRecordDTO.getDaoId());
        userCreatorPhoneRecord.insert();

    }


    /**
     * 修改手机号记录page
     * @param adminUserCreatorPhoneRecordDTO
     * @return
     */
    @Override
    public Page<AdminUserCreatorPhoneRecordVO> getUserCreatorPhoneRecordById(AdminUserCreatorPhoneRecordDTO adminUserCreatorPhoneRecordDTO) {
        Page<AdminUserCreatorPhoneRecordVO> userCreatorPhoneRecordById = userCreatorPhoneRecordDao.getUserCreatorPhoneRecordById(adminUserCreatorPhoneRecordDTO);
        List<AdminUserCreatorPhoneRecordVO> records = userCreatorPhoneRecordById.getRecords();
        for (AdminUserCreatorPhoneRecordVO record : records) {
            SysMember sysMember = sysMemberDao.getById(record.getModifyId());
            record.setModifyIdName(sysMember.getUserName());
        }
        return userCreatorPhoneRecordById;
    }



}
